package com.note7_12;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Question1 {

	public static void main(String[] args) throws Exception {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new File("src/com/note7_12/clothes.xml"));
		Element root = doc.getRootElement(); // 获取当前根节点
		System.out.println("当前根节点名为：" + root.getName());

		List<Element> list = root.selectNodes(".");// 选取当前节点 -> 根节点
		for (Element e : list) {
			System.out.println("当前节点名为：" + e.getName());

		}

		List<Element> list1 = root.selectNodes("//brand");// 根节点中名为brand的节点，不论位置在哪
		for (Element e1 : list1) {
			System.out.println("当前节点名为：" + e1.getText());
			List<Element> root0 = e1.selectNodes("..");// 选取当前节点的根节点
			for (Element e2 : root0)
				System.out.println("根节点为：" + e2.getName());
		}

	}
}
